Page({
  data: {
    customKeyboard: null,
    customCarNumInput: null,

    customCarNumInputIndex: 0
  },

  onLoad() {},

  onReady() {
    this.setData({
      customKeyboard: this.selectComponent('#customKeyboard'),
      customCarNumInput: this.selectComponent('#customCarNumInput')
    });

    this.changeKerboard(1);
  },

  changeKerboard(type) {
    this.data.customKeyboard.change(type);
    this.data.customKeyboard.show();
  },

  onInputFocus(e) {
    const index = e.detail;
    if (index == 0) {
      this.changeKerboard(1);
    } else if (index == 7) {
      this.changeKerboard(3);
    } else {
      this.changeKerboard(2);
    }
    this.setData({
      customCarNumInputIndex: index
    });
  },

  onKeyboardClick(e) {
    this.data.customCarNumInput.change({
      index: this.data.customCarNumInputIndex,
      value: e.detail,
      remove: false
    })
  },

  onKeyboardDelete(e) {
    this.data.customCarNumInput.change({
      index: this.data.customCarNumInputIndex,
      value: '',
      remove: true
    })
  },

  showCarNo(e) {
    wx.showModal({
      content: this.data.customCarNumInput.data.numbers.map(item => item.value).join('')
    })
  }
})